package org.vincen.helloworld.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxySubject implements InvocationHandler {

	private Object arg = null;
	
	//使用门面模式，和动态代理模式相结合，效果更好
	public Object getProxyInstance (Object arg) {
		this.arg = arg;
		return Proxy.newProxyInstance(arg.getClass().getClassLoader(), arg.getClass().getInterfaces(), this);
	}
	
	public Object invoke(Object arg0, Method arg1, Object[] arg2)
			throws Throwable {
		Object result = arg1.invoke(arg, arg2);
		return result;
	}
}
